const Auth = require("./utils/privacy_auth.js");
const UserInfo = require("./utils/privacy_userInfo.js");
const Update = require("./utils/version_update.js");
const Log = require("./utils/core_log.js");
const ServiceLogin = require("./service/service_login.js");

//app.js
App({
  onLaunch: function () {
    /* 版本更新 */
    Update.update();
    /** 登录检测 */
    ServiceLogin.isLogin(
      (res) => {
        this.globalData.isLogin = true
        this.globalData.user =  res.data.data.user;
        if (this.checkLoginReadyCallback) {
          Log.debug("App->onLaunch->isLogin", "首页.js 先加载完成", true)
          this.checkLoginReadyCallback(true, res)
        }else{
          Log.debug("App->onLaunch->isLogin", "app.js 先加载完成", true)
        }
      },
      (res) => {
        this.globalData.isLogin = false
        this.globalData.user = null;
        if (this.checkLoginReadyCallback) {
          Log.debug("App->onLaunch->isLogin", "首页.js 先加载完成", false)
          this.checkLoginReadyCallback(false, res)
        }else{
          Log.debug("App->onLaunch->isLogin", "app.js 先加载完成", false)
        }
      }
    );
    /** 获取用户信息 */
    Auth.checkAuth(Auth.AuthSetting.UserInfo, res=>{
      UserInfo.getUserInfo(false, (res, userInfo)=>{
        this.globalData.userInfo = userInfo
        if (this.userInfoReadyCallback) {
          this.userInfoReadyCallback(res)
        }
      });
    });
    
  },
  globalData: {
    isLogin: null,
    user: null,
    userInfo: null
  }
})